home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- int FadeMain(HANDLE hStream, ImagePluginApplyParams *psParams, int r, int g, int b, int bDouble, int bReverse)
- {
- int nSrcPercent, nLength, i;
- int nPos;
- ImageSample *psSrc, *psDst;
-
- nLength = psParams->dwWidth*psParams->dwHeight;
-
- // if reverse dir, change the frame pos appropriately.
- nPos = psParams->dwPos;
-
- psSrc = psParams->psSrcSample;
- psDst = psParams->psDstSample;
-
- nSrcPercent = (nPos*256)/(psParams->dwFrames-1);
- if (bDouble)
- {
- nSrcPercent = nSrcPercent*2;
- if (nSrcPercent > 256)
- nSrcPercent = 512-nSrcPercent;
- }
- if (bReverse)
- nSrcPercent=256-nSrcPercent;
-
- if (r >= 0)
- {
- // use the colour.
- memset(psDst, 255, nLength*sizeof(ImageSample));
- for (i=0; i<nLength; i++)
- {
- int c;
- c = psSrc[i].r; psDst[i].r = c+(((r-c)*nSrcPercent)>>8);
- c = psSrc[i].g; psDst[i].g = c+(((g-c)*nSrcPercent)>>8);
- c = psSrc[i].b; psDst[i].b = c+(((b-c)*nSrcPercent)>>8);
- }
- }
- else
- {
- // just modify alpha.
- memcpy(psDst, psSrc, nLength*sizeof(ImageSample));
- for (i=0; i<nLength; i++)
- psDst[i].a = (psDst[i].a*nSrcPercent)>>8;
- }
-
- return 0;
- }
-
- int FadeToBlack(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 0, 0, 0, 0);
- }
-
- int FadeToWhite(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 255, 255, 0, 0);
- }
-
- int FadeToRed(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 0, 0, 0, 0);
- }
-
- int FadeToGreen(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 255, 0, 0, 0);
- }
-
- int FadeToBlue(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 0, 255, 0, 0);
- }
-
- int FadeToCyan(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 255, 255, 0, 0);
- }
-
- int FadeToMagenta(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 0, 255, 0, 0);
- }
-
- int FadeToYellow(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 255, 0, 0, 0);
- }
-
- int FadeFromBlack(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 0, 0, 0, 1);
- }
-
- int FadeFromWhite(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 255, 255, 0, 1);
- }
-
- int FadeFromRed(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 0, 0, 0, 1);
- }
-
- int FadeFromGreen(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 255, 0, 0, 1);
- }
-
- int FadeFromBlue(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 0, 255, 0, 1);
- }
-
- int FadeFromCyan(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 0, 255, 255, 0, 1);
- }
-
- int FadeFromMagenta(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 0, 255, 0, 1);
- }
-
- int FadeFromYellow(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, 255, 255, 0, 0, 1);
- }
-
- int FadeIn(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, -1, 0, 0, 0, 0);
- }
-
- int FadeOut(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, -1, 0, 0, 0, 1);
- }
-
- int FadeInAndOut(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, -1, 0, 0, 1, 0);
- }
-
- int FadeOutAndIn(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return FadeMain(hStream, psParams, -1, 0, 0, 1, 1);
- }
-
-